using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Gameplay.City
{
    public class ObjectPool<T> where T : new()
    {
        // 对象池
        private Stack<T> _Pool;

        // 池里的对象数量
        public int Count => this._Pool.Count;
    
        public ObjectPool()
        {
            this._Pool = new Stack<T>();
        }
    
        /// <summary>
        /// 弹出对象
        /// </summary>
        /// <returns></returns>
        public T Pop()
        {
            if (this._Pool.Count > 0)
            {
                return this._Pool.Pop();
            }
            
            return new T();
        }
    
        /// <summary>
        /// 回收对象
        /// </summary>
        /// <param name="go"></param>
        public void Push(T go)
        {
            this._Pool.Push(go);
        }
    
    }
    
}